package com.zsrt.java.day20161227.wrl.demo03;

import java.util.Arrays;

import org.junit.Test;

public class ArrayAddTest01 {
	
	@Test
	public void add01(){
		int[] oldArrays = new int[]{1,2,3,4,5};
		
		int num = 9;
		int len = oldArrays.length;
		
		//1 造一个数组，类型一样，数组长度是原来的长度+1
		int[] newArrays = new int[len+1];
		
		//声明的数组int[]，初始值都为0
		System.out.println(Arrays.toString(newArrays));
		
		//2 把原来的数组中的值依次复制过来，循环
		for(int i=0;i<len;i++){
			//拿到老数组的值
			newArrays[i] = oldArrays[i];
		}
		System.out.println(Arrays.toString(newArrays));
		
		//添加元素
		newArrays[len] = num;
		System.out.println(Arrays.toString(newArrays));
	}

}
